package fr.inserm.u674.chcdbweb.model.DAO;

import fr.inserm.u674.chcdbweb.model.DTO.Tissue;

/**
 * Test harness for the fr.inserm.u674.chcdbweb.model.dao package. This require the following preconditions:
 * <ol>
 * <li>A MySQL server running at localhost:3306 with a database named 'TumeursDB'.
 * <li>A 'Tissue' table in the 'TumeursDB' database
 * <li>A MySQL user with the name 'chcdbweb' and password 'chcdbweb' which has sufficient rights on
 * the javabase.user table.
 * <li>A MySQL JDBC Driver JAR file in the classpath.
 * <li>A properties file 'dao.properties' in the classpath with the following entries:
 * <pre>
 * javabase.jdbc.driver = com.mysql.jdbc.Driver
 * javabase.jdbc.url = jdbc:mysql://localhost:3306/TumeursDB
 * javabase.jdbc.username = chcdbweb
 * javabase.jdbc.password = chcdbweb
 * </pre>
 * </ol>
 *
 * @author BalusC, thomas Burguiere
 * @link http://balusc.blogspot.com/2008/07/dao-tutorial-data-layer.html
 */
public class DAOTest {

	public static void main(String[] args) throws Exception {
		DAOFactory TumeursDBDAOFactory = DAOFactory.getInstance("TumeursDB.jdbc");
		System.out.println("DAOFactory successfully obtained : "+TumeursDBDAOFactory);
		
		TissueDAO tissueDAO = TumeursDBDAOFactory.getTissueDAO();
		System.out.println("TissueDAO successfully obtained : "+tissueDAO);
		
		//create Normal Tissue
		Tissue normalTissue = new Tissue(9999, "N");
		tissueDAO.createMaster(normalTissue);
		System.out.println("Tissue successfully created: " + normalTissue);
		
		//create Tumoral Tissue
//		Tissue tumoralTissue = new Tissue(9999, "T",9999);
//		tissueDAO.createTumoral(tumoralTissue);
//		System.out.println("Tissue successfully created: " + tumoralTissue);
		
		//update tissue
		normalTissue.setTissueComment("Dummy Tissue created via the DAOTest java class");
		tissueDAO.update(normalTissue);
		System.out.println("Tissue successfully updated: " + normalTissue);
		
		//list all Tissues
//		ArrayList<String> emptyList = null;
//		List<Tissue> tissues = tissueDAO.list(false, emptyList);
//        System.out.println("List of tissues successfully queried: " + tissues);
//        System.out.println("Thus, amount of tissues in database is: " + tissues.size());
        
        //delete Tissue
        tissueDAO.delete(normalTissue);
        System.out.println("Succesfully deleted tissue " + normalTissue);
        
        // Get another user by name and password.
        Tissue foundAnotherTissue = tissueDAO.find(1851, "T");
        System.out.println("Another tissue successfully queried: " + foundAnotherTissue);
		
	}

}
